package com.itao.poi.tl;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.Includes;
import com.deepoove.poi.util.PoitlIOUtils;
import com.itao.poi.tl.util.ResourceUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;

/**
 * 嵌套标签{{+lebalName}}
 *
 * @author sjt
 * @Date 2024/10/10 8:54
 */
public class NestLebal {

    public static void main(String[] args) throws Exception {
        XWPFTemplate template = XWPFTemplate.compile(ResourceUtil.getDocxPath("nest_template.docx"))
                .render(new HashMap<String, Object>() {
                            {
                                List<AddrModel> subData = List.of(
                                        new AddrModel("Hangzhou,China"),
                                        new AddrModel("Shanghai,China")
                                );
                                put("nested", Includes.ofLocal(
                                        ResourceUtil.getDocxPath("nest_sub_template.docx")
                                ).setRenderModel(subData).create());
                            }
                        }
                );
        FileOutputStream fos = new FileOutputStream(ResourceUtil.getDocxOutPath("nest_template.docx"));
        template.writeAndClose(fos);
        PoitlIOUtils.closeQuietlyMulti(template, fos);
    }

    @Data
    @AllArgsConstructor
    static class AddrModel {
        private String addr;
    }

}
